package com.draw.server.service;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.draw.core.Color;
import com.draw.server.hibernate.HibernateUtil;
import com.draw.webinterface.ColorInterface;

@WebService(targetNamespace = "http://draw.some.com/", serviceName = "ColorService", name = "ColorService")
public class ColorService implements ColorInterface {
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory
			.getLogger(ColorService.class);

	@Override
	public List<Color> getAllColor() {
		Session session = HibernateUtil.getSession();
		String req = "from com.draw.core.Color";
		Query query = session.createQuery(req);
		return extractedColors(query);
	}

	private List<Color> extractedColors(Query query) {
		ArrayList<Color> data = new ArrayList<Color>();
		for (Object obj: query.list() ) {
			data.add((Color) obj);
		}
		return data;
	}

}
